package com.alatus.web;

import com.alatus.constant.Constants;
import com.alatus.model.TActivityRemark;
import com.alatus.query.ActivityRemarkQuery;
import com.alatus.result.Result;
import com.alatus.service.ActivityRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
public class ActivityRemarkController {
    @Resource
    private ActivityRemarkService activityRemarkService;

    @PostMapping(value = "/api/activity/remark/add")
    public Result addActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery, @RequestHeader(value = Constants.TOKEN_NAME)String token){
        activityRemarkQuery.setToken(token);
        int save = activityRemarkService.saveActivityRemark(activityRemarkQuery);
        return save >= 1 ? Result.OK() : Result.FAIL();
    }

    @GetMapping(value = "/api/acitivity/remark")
    public Result activityRemarkPage(@RequestParam(value = Constants.CURRENT,required = false)Integer current, @RequestParam(value = Constants.ID)Integer id){
        if(current == null){
            current = 1;
        }
        ActivityRemarkQuery activityRemarkQuery = new ActivityRemarkQuery();
        activityRemarkQuery.setActivityId(id);
        PageInfo<TActivityRemark> remarkList = activityRemarkService.getActivityRemarkByPage(current,activityRemarkQuery);
        return Result.OK(remarkList);
    }
//    根据ID获取活动备注
//    @GetMapping(value = "/api/activty/remark/detail/{id}")
//    public R remarkDetail(@PathVariable(value = Constants.ID)Integer id){
//        TActivityRemark tActivityRemark = activityRemarkService.getActivityRemarkById(id);
//        return R.OK(tActivityRemark);
//    }
    @PutMapping(value = "/api/activity/remark/edit")
    public Result editActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery, @RequestHeader(value = Constants.TOKEN_NAME)String token){
        activityRemarkQuery.setToken(token);
        int update = activityRemarkService.updateActivityRemark(activityRemarkQuery);
        return update >= 1 ? Result.OK() : Result.FAIL();
    }

    @DeleteMapping(value = "/api/activity/remark/delete/{id}")
    public Result delActivityRemark(@PathVariable(value = Constants.ID)Integer id){
        int result = activityRemarkService.deleteActivtyRemarkById(id);
        return result >= 1 ? Result.OK() : Result.FAIL();
    }
}
